// pages/mine/mine.js
import { lgRequest } from '../../utils/ajax'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    photer:'https://www.mengbaoonline.com:8182/profile/upload/2022/11/22/9de0d78010b2428255eeabfae35a0e0a.png',
    mineInfo:{},
    statusBarHeight: getApp().globalData.statusBarHeight,
    titleBarHeight: getApp().globalData.titleBarHeight,
    delectImgTag: "https://www.mingchuliangzao.com.cn:8632/profile/upload/2022/07/19/713a49f43240fae4d44090d92d7f9cf6.png",
    isShow:false
  },
  // 打开密码重置
  toggleMM(){
    this.setData({
      isShow:true
    })
  },
  // 关闭密码重置
  onClose(){
    this.setData({
      isShow:false
    })
  },
  // 手机密码和验证码
  password(e){
    // console.log(e.detail.value);
    this.setData({
      password:e.detail.value
    })
  },
  Code(e){
    this.setData({
      code:e.detail.value
    })
  },
  // 重置密码
  chongzhi(){
    
    wx.request({
      url: `https://www.mengbaoonline.com:8182/system/user/appLogin`,
      data:{
         phonenumber : this.data.mineInfo.phonenumber,
         password : this.data.password,
         code : this.data.code
      },
      method: 'put',
      dataType: 'json',
      header: {
        'content-type': 'application/json',
        // 'Authorization': wx.getStorageSync('token'),
        // 'headerUserId': user.id,
        // 'headerUserToken': user.userToken
      },
      success: (res) => {
        console.log(res,'res');
        wx.showToast({
                title: res.data.msg,
              })
              this.setData({
                isShow:false
              })
      },
    });
  },
  // 获取验证码
  getCode(){
    let phone=this.data.mineInfo.phonenumber
    // let params = {
    //   phone:this.data.mineInfo.phonenumber
    // }
    console.log(phone);
    // lgRequest("yanzhengma", params, {
    //   doSuccess: (r) => {
    //     wx.showToast({
    //       title: '获取成功',
    //     })
    //   }
    // })

    wx.request({
      url: `https://www.mengbaoonline.com:8182/duanxin/fasong/send2?phone=${phone}`,
      method: 'GET',
      dataType: 'json',
      header: {
        'content-type': 'application/json',
        // 'Authorization': wx.getStorageSync('token'),
        // 'headerUserId': user.id,
        // 'headerUserToken': user.userToken
      },
      success: (res) => {
        console.log(res);
        wx.showToast({
                title: '获取成功',
              })
      },
    });
  },
  /**
   * 退出登录
   */
  layOut() {
    wx.showLoading({
      title: '正在退出登录...',
    })
    let params = {
      token: wx.getStorageSync('token')
    }
    lgRequest('logout', params, {
      errAlert: false,
      doSuccess: r => {
        if (r.code == 200) {
          wx.removeStorageSync('token')
          wx.reLaunch({
            url: '../login/login',
          })
        } else {
          wx.showToast({
            title: r.msg,
            icon: 'none'
          })
        }
      },
      doComplete: r => {
      }
    })
  },
  /**
   * 我的巡查记录
   */
  historyList(e){
    let type = e.currentTarget.dataset.type
    switch(type){
      case'0':
        wx.navigateTo({
          url: `../minePage/patrolRecord/patrolRecord?userId=${this.data.mineInfo.userId}`,
        })
        break;
      case'1':
        wx.navigateTo({
          url: `../minePage/myOrder/myOrder?userId=${this.data.mineInfo.userId}`,
        })
        break;
      case'2':
        wx.navigateTo({
          url: `../minePage/permisseInformation/permisseInformation?userId=${this.data.mineInfo.userId}`,
        })
        break;
        case'3':
        wx.navigateTo({
          // pages/device/device
          url: '../device/device',
        })
        break;
    }
  },
  /**
   * 获取个人信息
   */
  useinto(){
    let params = {
      token: wx.getStorageSync('token')
    }
    lgRequest('useinto', params, {
      errAlert: false,
      doSuccess: r => {
        if (r.code == 200) {
          this.setData({
            mineInfo:r.data.user
          })
        } else {
          wx.showToast({
            title: r.msg,
            icon: 'none'
          })
        }
      },
      doComplete: r => {
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.useinto()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})